package controller;


import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import po.Student;
import po.User;
import service.StudentService;


@Controller
public class studentController {
	
	// 依赖注入
	@Autowired
	private StudentService studentService;	
	@RequestMapping(value = "/student/getStudent.action")
	public String list( Model model) {
		List<Student> studentlist = studentService.getStudentList();
		model.addAttribute("studentlist", studentlist);	
		return "student_list";

	}
	@RequestMapping("/student/delStudent.action")
	public String studentDelete(Integer studentid) {
		int rows = studentService.deleteStudent(studentid);
		if(rows > 0) {
			System.out.println("OK");
		}else {
			System.out.println("FAIL");
		}
		return "redirect:/student/getStudent.action";
	}
	@RequestMapping("/student/addStudent.action")
	public String studentAdd(Student student) {
		int rows = studentService.addStudent(student);
		if(rows > 0) {
			System.out.println("OK");
		}else {
			System.out.println("FAIL");
		}
		return "redirect:/student/getStudent.action";
	}
	
	@RequestMapping(value ="/student/getstudentId.action")
	@ResponseBody
	public Student getStudentId(Integer id) {
		Student data = studentService.getStudentId(id);
		return data;
   }  
	
	@RequestMapping(value ="/student/updateStudent.action")
	@ResponseBody
	public String updateWinner(Student student) {
		int row = studentService.updateStudent(student);
		if(row>0) {
			return "OK";
		}else {
			return "false";
		}
   }
	@RequestMapping(value = "/student/findAll.action")
	public String listAll(String data,Model model) {	
		List<Student> studentlist = studentService.findList(data);
		model.addAttribute("studentlist", studentlist);	
		System.out.println("data2"+data);
		return "student_list";
	}
}
